package plugins

import (
	"time"

	"github.com/prometheus/client_golang/prometheus"
)

// Plugin defines the interface that all metric collector plugins must implement
type Plugin interface {
	// Name returns the unique name of the plugin
	Name() string

	// Init initializes the plugin with its configuration
	Init(config map[string]interface{}) error

	// Start starts the metric collection
	Start() error

	// Stop stops the metric collection
	Stop() error

	// Collect triggers an immediate collection of metrics
	Collect() error

	// GetMetrics returns all metrics collected by this plugin
	GetMetrics() []prometheus.Collector

	// GetInterval returns the collection interval
	GetInterval() time.Duration
}

// BasePlugin provides common functionality for plugins
type BasePlugin struct {
	name     string
	interval time.Duration
	enabled  bool
	metrics  []prometheus.Collector
}

// NewBasePlugin creates a new base plugin with the given name
func NewBasePlugin(name string) *BasePlugin {
	return &BasePlugin{
		name:    name,
		enabled: true,
		metrics: make([]prometheus.Collector, 0),
	}
}

// Name returns the plugin name
func (b *BasePlugin) Name() string {
	return b.name
}

// SetInterval sets the collection interval
func (b *BasePlugin) SetInterval(interval time.Duration) {
	b.interval = interval
}

// GetInterval returns the collection interval
func (b *BasePlugin) GetInterval() time.Duration {
	return b.interval
}

// SetEnabled sets whether the plugin is enabled
func (b *BasePlugin) SetEnabled(enabled bool) {
	b.enabled = enabled
}

// IsEnabled returns whether the plugin is enabled
func (b *BasePlugin) IsEnabled() bool {
	return b.enabled
}

// AddMetric adds a new metric to the plugin
func (b *BasePlugin) AddMetric(metric prometheus.Collector) {
	b.metrics = append(b.metrics, metric)
}

// GetMetrics returns all metrics for this plugin
func (b *BasePlugin) GetMetrics() []prometheus.Collector {
	return b.metrics
} 